<?php
require_once("db.php");

//---------------------------
// MakeAllowedQuestionsSelectionTable
//---------------------------
function MakeAllowedQuestionsSelectionTable($userid)
{
	global $def_height, $numdir;

	GetUserInfo($userid, &$userinfo);
	GetQuestionStatusForUser($userid, $allowed_questions, $not_allowed_questions, $all_questions);
	
	$ncols = 13;
	$height = floor($def_height/2)+1;

	$ret_str = "<table border='1'>\n";
	$ret_str .= "  <tr class='color13'>\n";
	$ret_str .= "    <th colspan='$ncols'>Allowed Questions for ".$userinfo["first_name"]." (".$userinfo["username"].")</th>\n";
	$ret_str .= "  </tr>\n";
	$ret_str .= "  <tr class='color12'>\n";
	$ret_str .= "    <th colspan='$ncols'><font size='-1'>(deselect all to allow any question)</font></th>\n";

	// Loop over all questions
	$Nshown = 0;
	$ret_str .= "  <tr>\n";
	foreach($all_questions AS $questionid){
		GetQuestion($questionid, &$num1, &$num2, &$operator, &$answer);
		$checked = in_array($questionid, $allowed_questions) ? "CHECKED":"";
		$ret_str .= "		<td><input type='checkbox' name='q$questionid' $checked>";
		$ret_str .= get_number_html($num1, $height);
		$ret_str .= "<img height='$height' src='$numdir/${operator}.png'>";
		$ret_str .= get_number_html($num2, $height);
		$ret_str .= "		</td>";
		
		$Nshown++;
		if($Nshown%$ncols == 0)$ret_str .= "</tr>\n<tr>\n";
	}
	$nleft = $ncols - ($Nshown%$ncols);
	if($nleft != $ncols)$ret_str .= "<td colspan='$nleft'></td>";
	$ret_str .= "</tr>\n";

	$ret_str .= "</table>\n";
	
	return $ret_str;
}

?>